import { _decorator, Component, instantiate, Node, Prefab } from 'cc';
import { UserInfo } from '../common/UserInfo';
import { Village } from '../entity/Village';
import { PalaceVillage } from './PalaceVillage';
const { ccclass, property } = _decorator;

@ccclass('PalaceExpand')
export class PalaceExpand extends Component {
    @property(Node)
    empty:Node
    @property(Node)
    content:Node
    @property(Prefab)
    palaceVillage:Prefab

    start() {
        this.init()
    }

    init(){
        let list = UserInfo.instance.villageData.subVillageList
        for(let i =0; i < list.length; i++){
            let item = list[i]
            let village = Village.createByVillageObj(item)
            let node = instantiate(this.palaceVillage)
            this.content.addChild(node)
            node.getComponent(PalaceVillage).setData(village, i+1)
        }

        if(list.length > 0){
            this.empty.active = false
        }

    }
    
}


